package aimozg.joglfw.figures;

import aimozg.joglfw.JoglApplication;
import aimozg.joglfw.Renderable;

import javax.media.opengl.GL;

/**
* Created by IntelliJ IDEA.
* User: aimozg
* Date: 06.01.11
* Time: 14:12
*/
public class Figure implements Renderable {
	private final PaletteSource paletteSource;
	private final Primitive[] primitives;

	public Figure(PaletteSource paletteSource, Primitive... primitives) {
		this.paletteSource = paletteSource;
		this.primitives = primitives;
	}

	public Figure clone() {
		return new Figure(paletteSource, primitives);
	}

	public Figure clone(PaletteSource paletteSource) {
		return new Figure(paletteSource, primitives);
	}

	@Override
	public void render(JoglApplication app) {
		Palette palette = (paletteSource==null)?null:paletteSource.getPalette();
		app.gl().glEnableClientState(GL.GL_VERTEX_ARRAY);
		for (Primitive primitive : primitives) {
			primitive.renderFast(app, palette);
		}
		app.gl().glDisableClientState(GL.GL_VERTEX_ARRAY);
	}
}
